// pages/index/subPages/home/home.js
import tool from '../../../../modules/tool'
import store from '../../../../modules/store'
import config from '../../../../config'

Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    ...store.getItem('windowInfo'),
    showTitleBar: false,
    title: config.name
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleLongPress() {
      if(store.getItem('showDeveloperInfo')){
        tool.handleShowModel(`小程序开发者
聊城大学计算机学院2022级人工智能1班张天予
电话：17853441627`,false)
      }
    },
    handleScan() {
      tool.handleScan()
    },
    handleItemClick(e) {
      e = e.currentTarget.dataset
      tool.handleShowProductActivityDetailPage(e.ispro, e.id)
    },
    async handleFourButtonsClick(e) {
      e = e.currentTarget.dataset.index
      switch (e) {
        case 1:
          store.setItem('mainCurrentPageIndex', 1)
          break;
        case 2:
          store.setItem('mainCurrentPageIndex', 2)
          break;
        case 3:
          tool.handleShowCart()
          break;
        case 4:
          tool.showMyOrderPage()
          break;
      }
    },
    handleScroll(e) {
      if (e.detail.scrollTop < 10) {
        this.setData({
          showTitleBar: false
        })
      } else {
        this.setData({
          showTitleBar: true
        })
      }
    }
  },

  attached() {
    try {
      this.setData(store.getItem('windowInfo'))
    } catch (error) {

    }
    store.onChange('windowInfo', () => {
      this.setData(store.getItem('windowInfo'))
    })

    this.setData({
      activities: store.getItem('homeActivities'),
      products: store.getItem('homeProducts'),
    })
  },

  async created() {

  }
})